package util

// 创建一个包含从 start 到 end，但不包含 end 本身范围数字的数组。
// 如果 end 小于 start ，会创建一个空数组，除非指定了 step。
// step 如果为 0 则为默认值。

import "gitee.com/big_meteor/godash/math"

const (
	StepUInt   uint   = 1
	StepUInt64 uint64 = 1
)

func RangeInt(start, end int, step ...uint) []int {
	if start == end {
		return []int{}
	}

	var _step = int(StepUInt)
	if 0 < len(step) && 0 < step[0] {
		_step = int(step[0])
	}

	var vLen = int(math.Ceil(float64(math.AbsInt(end-start)) / float64(_step)))
	var v = make([]int, vLen)

	if start > end {
		_step = -_step
	}

	for i := 0; i < vLen; i++ {
		v[i] = start
		start += _step
	}

	return v
}

func RangeInt64(start, end int64, step ...uint) []int64 {
	if start == end {
		return []int64{}
	}

	var _step = int64(StepUInt)
	if 0 < len(step) && 0 < step[0] {
		_step = int64(step[0])
	}

	var vLen = int(math.Ceil(float64(math.AbsInt64(end-start)) / float64(_step)))
	var v = make([]int64, vLen)

	if start > end {
		_step = -_step
	}

	for i := 0; i < vLen; i++ {
		v[i] = start
		start += _step
	}

	return v
}

func RangeUInt(start, end uint, step ...uint) []uint {
	if start >= end {
		return []uint{}
	}

	var _step = StepUInt
	if 0 < len(step) && 0 < step[0] {
		_step = step[0]
	}

	var vLen = int(math.Ceil(float64(end-start) / float64(_step)))
	var v = make([]uint, vLen)

	for i := 0; i < vLen; i++ {
		v[i] = start
		start += _step
	}

	return v
}

func RangeUInt64(start, end uint64, step ...uint64) []uint64 {
	if start >= end {
		return []uint64{}
	}

	var _step = StepUInt64
	if 0 < len(step) && 0 < step[0] {
		_step = step[0]
	}

	var vLen = int(math.Ceil(float64(end-start) / float64(_step)))
	var v = make([]uint64, vLen)

	for i := 0; i < vLen; i++ {
		v[i] = start
		start += _step
	}

	return v
}
